package java0423;

import java.util.Stack;

public class Main {
    public static int getLCA(int a, int b) {
        // write code here
        Stack<Integer> stacka = new Stack<>();
        Stack<Integer> stackb = new Stack<>();
        while (a > 0) {
            stacka.push(a);
            a /= 2;
        }
        while (b > 0) {
            stackb.push(b);
            b /= 2;
        }
        int ret = 1;
        while (stacka.isEmpty() == false && stackb.isEmpty() == false) {
            if (stacka.peek() != stackb.peek()) {
                return ret;
            }
            ret = stacka.pop();
            stackb.pop();
        }
        return ret;
    }
    public static void main(String[] args) {
        System.out.println(getLCA(1000, 1000));

    }
}
